package com.appcenter.task.controller;

import com.appcenter.jz.config.ErrorJsonResult;
import com.appcenter.jz.config.JsonResult;
import com.appcenter.task.input.LoadAlreadyTaskListPageInput;
import com.appcenter.task.input.SearchAlreadyTaskListInput;
import com.appcenter.task.service.AlreadyTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/services/jztaskcenterservice/alreadytask")
@Api(value="已办任务",description = "已办任务")
public class AlreadyTaskCenterController {
    @Autowired
    AlreadyTaskService alreadyTaskService;

    @ApiOperation(value = "查询已办信息", notes = "查询已办信息",produces = "application/json")
    @PostMapping("/searchalreadytasklist")
    public ResponseEntity<JsonResult> SearchAlreadyTaskList(@RequestBody SearchAlreadyTaskListInput input) throws Exception {
        JsonResult r = new JsonResult();
        try {
            r.setResult(alreadyTaskService.SearchAlreadyTaskList(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "加载已办信息", notes = "加载已办信息",produces = "application/json")
    @PostMapping("/loadalreadytasklistpage")
    public ResponseEntity<JsonResult> LoadAlreadyTaskListPage(@RequestBody LoadAlreadyTaskListPageInput input) throws Exception {
        JsonResult r = new JsonResult();
        try {
            r.setResult(alreadyTaskService.LoadAlreadyTaskListPage(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
}
